package com.iwayin.core.dao.follow;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.iwayin.core.dao.BaseDAOImpl;
import com.iwayin.core.dataobject.FollowDO;

public class FollowDAOImpl extends BaseDAOImpl implements FollowDAO {

	@Override
	public void addFollow(FollowDO follow) {
		executeInsert("FollowDAO.addFollow", follow);
	}

	@Override
	public void deleteFollow(FollowDO follow) {
		executeDelete("FollowDAO.deleteFollow", follow);
	}

	@Override
	public FollowDO getFollower(Long userId, Long followId) {
		Map<String, Long> param = new HashMap<String, Long>();
		param.put("userId", userId);
		param.put("followId", followId);
		return (FollowDO) queryForObject("FollowDAO.getFollower", param);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<FollowDO> findFollowList(FollowDO query) {
		return executeQueryForList("FollowDAO.findFollowList", "FollowDAO.findFollowList.count", query);
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public List<Long> findAllFollowByUserId(Long userId){
		return this.getSqlMapClientTemplate().queryForList("FollowDAO.findAllFollowByUserId",userId);
	}
	@Override
	public List<FollowDO> findFollowMostToday(Long size) {
		return queryForList("FollowDAO.findMostFollowToday",size);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Long> findFollowsFollows(List<Long> userIds) {
		HashMap<String, List<Long>> params = new HashMap<String, List<Long>>();
		params.put("userIds", userIds);
		return this.getSqlMapClientTemplate().queryForList("FollowDAO.findFollowsFollows", params);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Long> findManuFriendList(Long userId) {
		List<Long> followIds = this.findAllFollowByUserId(userId);
		if(followIds!=null){
			HashMap<String,Object> params = new HashMap<String, Object>();
			params.put("followIds", followIds);
			params.put("userId",userId);
			return this.getSqlMapClientTemplate().queryForList("FollowDAO.findManuFriendList", params);
		}
		return null;
	}
}
